package com.cheng.reggie.mapper;

import com.cheng.reggie.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ShoppingCartMapper {


    //减少修改购物车数量
    //    @Update("update shopping_cart set number=#{number} where id=#{id}")
    Integer updateShoppingCart(ShoppingCart shoppingCart);

    //删除购物车数量
    //    @Delete("delete from shopping_cart where id =#{id}")
    void deleteShoppingCart(ShoppingCart shoppingCart);

    //查询购物车中当前菜品dishId或者套餐setmealId购物车数据
    ShoppingCart findByShoppingCart(ShoppingCart shoppingCart);


    //更新指定购物车菜品数据数量,根据购物车主键更新数量
    @Update("update shopping_cart set number=#{number} where id=#{id} ")
    Integer updateNumber(@Param("id") Long id,@Param("number") Integer number);

    //插入新的一条购物车数据
    @Insert("insert  into shopping_cart values(null,#{name},#{image},#{userId}," +
            "#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime}) ")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    Integer save(ShoppingCart shoppingCart);

    //查询指定用户的购物车集合
    @Select(("select * from shopping_cart where user_id=#{userId}"))
    List<ShoppingCart> findAllByUserId(Long userId);

    //通过用户id进行购物车物理删除
    @Delete(("delete from shopping_cart where user_id=#{userId}"))
    void deleteByUserId(Long userId);







}
